<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>新增工资记录</title>
    <style>
        body { font-family: Arial, sans-serif; }
        .container { max-width: 800px; margin: 0 auto; }
        .header { background-color: #4CAF50; color: white; padding: 15px; }
        .nav { overflow: hidden; background-color: #333; }
        .nav a { float: left; display: block; color: white; text-align: center; padding: 14px 16px; text-decoration: none; }
        .nav a:hover { background-color: #ddd; color: black; }
        .content { padding: 20px; }
        .form-group { margin-bottom: 15px; }
        .form-group label { display: block; margin-bottom: 5px; }
        .form-group input, .form-group select { width: 100%; padding: 8px; }
        .btn { background-color: #4CAF50; color: white; padding: 10px 15px; border: none; cursor: pointer; }
        .btn:hover { background-color: #45a049; }
        .back-btn { background-color: #f44336; color: white; padding: 10px 15px; border: none; cursor: pointer; text-decoration: none; }
        .back-btn:hover { background-color: #d32f2f; }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <h1>新增工资记录</h1>
    </div>

    <div class="nav">
        <a href="index.jsp">首页</a>
        <a href="employeeList.jsp">员工管理</a>
        <a href="departmentList.jsp">部门管理</a>
        <a href="salaryList.jsp">工资管理</a>
        <a href="#">系统设置</a>
    </div>

    <div class="content">
        <form action="saveSalary.jsp" method="post">
            <div class="form-group">
                <label>员工：</label>
                <select name="employee_id">
                    <%
                        Connection conn = null;
                        Statement stmt = null;
                        ResultSet rs = null;

                        try {
                            Class.forName("com.mysql.jdbc.Driver");
                            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/company", "root", "password");
                            stmt = conn.createStatement();
                            String sql = "SELECT employee_id, name FROM employees";
                            rs = stmt.executeQuery(sql);

                            while (rs.next()) {
                    %>
                    <option value="<%= rs.getInt("employee_id") %>"><%= rs.getString("name") %></option>
                    <%
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        } finally {
                            try {
                                if (rs != null) rs.close();
                                if (stmt != null) stmt.close();
                                if (conn != null) conn.close();
                            } catch (SQLException se) {
                                se.printStackTrace();
                            }
                        }
                    %>
                </select>
            </div>
            <div class="form-group">
                <label>月份：</label>
                <input type="month" name="month" required>
            </div>
            <div class="form-group">
                <label>基本工资：</label>
                <input type="number" name="base_salary" step="0.01" required>
            </div>
            <div class="form-group">
                <label>奖金：</label>
                <input type="number" name="bonus" step="0.01" value="0">
            </div>
            <div class="form-group">
                <label>扣除：</label>
                <input type="number" name="deduction" step="0.01" value="0">
            </div>
            <button type="submit" class="btn">保存</button>
            <a href="salaryList.jsp" class="back-btn">返回</a>
        </form>
    </div>
</div>
</body>
</html>
